package com.dyz.leetcode._02_string;

public class _245_reverseVowels {
    public String reverseVowels(String s) {
        int n = s.length();
        int start = 0;
        int end = n-1;
        char [] chars = s.toCharArray();
        while(start<=end){
            while(start<=end && !isVowels(chars[start])){start++;}
            while(end>=start && !isVowels(chars[end])){end--;}
            if(start<=end){
                char temp = chars[start];
                chars[start] = chars[end];
                chars[end] = temp;
                start++;
                end--;
            }
        }
        return new String(chars);

    }

    private boolean isVowels(char c){
        if (c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U'){
            return true;
        }
        return false;
    }
}
